package com.ljc.www.rabbitmqdirectprovider;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


/**
 * 消息生产者/提供者
 */
@Component
public class Sender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Value("${mq.config.exchange}")
    private String exchange;

    @Value("${mq.config.queue.info.routing.key}")
    private String routingkey;

    @Value("${mq.config.queue.error.routing.key}")
    private String routingErrorKey;

    /**
     * 发送消息
     * @param msg
     */
    public void sendInfo(String msg){
        //向消息队列发送消息
        //参数一：交换机名称
        //参数二：路由键
        //参数三：消息
        amqpTemplate.convertAndSend(exchange,routingErrorKey,msg);
    }


    /**
     * 发送消息
     * @param msg
     */
    public void sendError(String msg){
        //向消息队列发送消息
        //参数一：交换机名称
        //参数二：路由键
        //参数三：消息
        amqpTemplate.convertAndSend(exchange,routingkey,msg);
    }



}
